package com.songaw.cangku.pojo.domain;

import com.songaw.cangku.pojo.entity.AppAccount;
import lombok.Data;
import org.apache.ibatis.session.RowBounds;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * TODO
 *
 * @author songaw
 * @date 2018/4/1 17:12
 */
@Data
public class AppLoginVo extends AppAccount implements UserDetails {

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // 根据自定义逻辑来返回用户权限，如果用户权限返回空或者和拦截路径对应权限不同，验证不通过
        String type = getType();

        if("1".equals(type)){
            List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
            GrantedAuthority au = new SimpleGrantedAuthority("role_chegong");
            list.add(au);
            return list;
        }else if("0".equals(type)){
            List<GrantedAuthority> list = new ArrayList<GrantedAuthority>();
            GrantedAuthority au = new SimpleGrantedAuthority("role_fahuoyuan");
            list.add(au);
            return list;
        }
        return null;
    }

    @Override
    public String getUsername() {
        return getEmplno();
    }

    /*
      *帐号是否不过期，false则验证不通过
      */
    public boolean isAccountNonExpired() {
        return true;
    }

    /*
     * 帐号是否不锁定，false则验证不通过
     */
    public boolean isAccountNonLocked() {
        return true;
    }

    /*
     * 凭证是否不过期，false则验证不通过
     */
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return "0".equals(getDeleteFlag());
    }
}
